package com.chaoyi.service.Impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.NovelMapper;
import com.chaoyi.model.Novel;
import com.chaoyi.service.NovelService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class NovelServiceImpl implements NovelService{
	@Resource
	NovelMapper novelMapper;

	@Override
	public List<Novel> findList(String offset, String limit) {
		return novelMapper.findList(offset,limit);
	}

	@Override
	public int findCount() {
		return novelMapper.findCount();
	}

	@Override
	public int saveNovel(Novel entity) {
		return novelMapper.saveNovel(entity);
	}

	@Override
	public Novel findNovelOne(int id) {
		return novelMapper.findNovelOne(id);
	}

	@Override
	public int alertNovelSave(Novel entity) {
		return novelMapper.alertNovelSave(entity);
	}

	@Override
	public int deleteNovel(int id) {
		return novelMapper.deleteNovel(id);
	}

	@Override
	public String uploadOSS(Part uploadFile) throws Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.fictionPath, fileName);
	}

	@Override
	public List<Novel> findListByType(String offset, String limit, int type) {
		return novelMapper.findListByType(offset,limit,type);
	}
}
